/*
 * Copyright 2006 Kevin Wetzels
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package drest.service;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;

/**
 * Base class for HTTP REST services.
 */
public class HttpRestService {

    /**
     * Http client to use for performing calls.
     */
    protected HttpClient client;

    /**
     * Constructor.
     */
    public HttpRestService() {
        client = new HttpClient();
    }

    /**
     * Creates a get method with the correct user agent set.
     *
     * @param url url for the get method
     *
     * @return the get method
     */
    protected GetMethod createGetMethod(String url) {
        GetMethod method = new GetMethod(url);
        method.setRequestHeader("Accept", "application/xml");
        System.out.println("url: " + url);
        return method;
    }

    /**
     * Creates a post method with the correct user agent set.
     *
     * @param url url for the post method
     *
     * @return the post method
     */
    protected PostMethod createPostMethod(String url) {
        PostMethod method = new PostMethod(url);
        method.setRequestHeader("Accept", "application/xml");        
        return method;
    }

}
